#include <iostream>
using namespace std;

template<typename T>
class smart_pointer
{
private:
    T* myrawpointer;
public:
    smart_pointer(T* pData):myrawpointer(pData){} //构造函数 将pData存入指针变量 myrawpointer
    ~smart_pointer(){delete myrawpointer;};
    //复制构造函数
    smart_pointer(const smart_pointer& anotherSP);
    //赋值构造函数
    smart_pointer& operator=(const smart_pointer& anotherSP);
    //重定义操作符* 和 -> 返回对象指针
    T& operator* () const
    {
        return *(myrawpointer);
    }

    T* operator ->() const
    {
        return myrawpointer;
    }
};

class Test
{
public:
    string name = "zhangsan";
    void DisplayName(void)
    {
        cout << name << endl;
    }
};

int main(int argc, char const *argv[])
{
    smart_pointer<Test>psmartTest(new Test);
    psmartTest->DisplayName();
    return 0;
}
